package edu.rit.hvz.android;

import edu.rit.hvz.android.DataLayer.MainDBAdapter;
import edu.rit.hvz.android.DataLayer.ServerDatabaseConnection;
import android.app.Activity;
import android.app.Application;
import android.app.LocalActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import android.widget.Toast;

public class HVZActivity extends TabActivity{
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		MainDBAdapter.initiateDatabase(this);
		ServerDatabaseConnection.poplulateDatabase(this);
		
		Utils.onActivityCreateSetTheme(this);
		Utils.setAct(this);
		setContentView(R.layout.main);

		Resources res = getResources(); // Resource object to get Drawables
		final TabHost tabHost = getTabHost(); // The activity TabHost
		TabHost.TabSpec spec; // Resusable TabSpec for each tab
		Intent intent; // Reusable Intent for each tab

		// News Feed Tab
		intent = new Intent().setClass(this, NewsFeed.class);
		spec = tabHost.newTabSpec("newsFeed").setIndicator("News", null)
				.setContent(intent);
		tabHost.addTab(spec);

		// Mission Feed Tab
		intent = new Intent().setClass(this, MissionFeed.class);
		spec = tabHost.newTabSpec("missionFeed")
				.setIndicator("Missions", null).setContent(intent);
		tabHost.addTab(spec);

		// Submit Tag Tab
		intent = new Intent().setClass(this, SubmitTag.class);
		spec = tabHost.newTabSpec("submitTag").setIndicator("Submit Tag", null)
				.setContent(intent);
		tabHost.addTab(spec);

		// Leader Board Tab
		intent = new Intent().setClass(this, LeaderBoards.class);
		spec = tabHost.newTabSpec("leaderBoards").setIndicator("Players", null)
				.setContent(intent);
		tabHost.addTab(spec);

		// Profile Tab
		intent = new Intent().setClass(this, Profile.class);
		spec = tabHost.newTabSpec("profile").setIndicator("Profile", null)
				.setContent(intent);
		tabHost.addTab(spec);

		// Radar Tab
		intent = new Intent().setClass(this, Radar.class);
		spec = tabHost.newTabSpec("radar").setIndicator("Radar", null)
				.setContent(intent);
		tabHost.addTab(spec);
		
		resizeTabs(tabHost.getTabWidget());

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater mInflater = getMenuInflater();
		mInflater.inflate(R.layout.menu, menu);
		return super.onCreateOptionsMenu(menu);

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.settings:
			this.startActivity(new Intent(this, Preferences.class));
			return true;
		}
		return false;
	}
	
	private void resizeTabs(TabWidget tabWidget){
		for(int i=0; i < tabWidget.getChildCount(); i++) {
			tabWidget.getChildAt(i).setLayoutParams(new 
					LinearLayout.LayoutParams(120,60)); 
		}
	}
}